package sc.common.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.springframework.util.CollectionUtils;

import sc.prototype.common.ConsoleUtil;

public class ListUtil implements ConsoleUtil {

    public static <T> ArrayList<T> newArrayList(T... ts) {
        if (ts == null) {
            return null;
        }
        ArrayList<T> ret = new ArrayList<T>();
        for (T t : ts) {
            ret.add(t);
        }
        return ret;
    }

    /**
     *
     * @param beginPos 从0开始
     */
    public static <T> void print(String prefix, Collection<T> coll, int count) {
        Console.info("{}，打印：{}行", prefix, count);
        if (CollectionUtils.isEmpty(coll)) {
            Console.info("共0行，列表为null！");
            return;
        }
        int size = coll.size();
        Console.info("共{}行", size);
        if (size > 0) {
            Iterator<T> it = coll.iterator();
            T cur = null;
            while (--count >= 0) {
                if (it.hasNext()) {
                    cur = it.next();
                } else {
                    Console.info("无更多数据！");
                    break;
                }
                Console.info("{}", cur);
            }
        }
    }
}
